<template>
  <div class="zhong">
    <VanButton type="primary" @click="onClick">按钮</VanButton>
  </div>
</template>

<script setup>
import { ref, reactive, computed, onMounted } from "vue";
import { login } from "@/api/index.js";
import router from "@/router";
import { setToken } from "@/utils/auth";

onMounted(() => {
  console.log("66666");
});

const onClick = async () => {
  console.log("click");
  try {
    const res = await login({
      username: "admin",
      password: "123456",
      rememberMe: true,
    });
    setToken(JSON.stringify(res));
    router.replace({ path: "/index" });
  } catch (error) {
    console.log("error:", error);
  }
};
</script>

<style lang="less" scoped>
.zhong {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
